package 笔试.腾讯;

import 算法.NiuKe.ListNode;

/**
 * @author:谢君臣
 * @Date:2021/8/22-20:03
 * @version:1.0
 * @function:
 */
public class Main01 {
    public static void main(String[] args) {
        ListNode listNode = new ListNode(1,new ListNode(2,new ListNode(3,new ListNode(4,new ListNode(5,new ListNode(6))))));
        ListNode[] solve = solve(4, listNode);
        System.out.println(solve);
    }
    public static ListNode[] solve (int m, ListNode a) {
        // write code here
        ListNode[] nodes = new ListNode[m];
        ListNode[] tail = new ListNode[m];
        if (a==null) {
            return nodes;
        }
        ListNode temp = a;
        while (temp!=null){
            int num = temp.val%m;
            ListNode node = new ListNode(temp.val);
            if (tail[num]==null){
                tail[num] = node;
                nodes[num] = node;
            }else {
                tail[num].next = node;
            }
            tail[num] = node;
            temp = temp.next;
        }
        return nodes;
    }
}
